﻿using Lufei_CaterBLL;
using Lufei_CaterModel;
using Lufei_CaterUI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using static System.Net.Mime.MediaTypeNames;


namespace ItcastCater
{
    public partial class FrmChangeProduct : Form
    {
        public FrmChangeProduct()
        {
            InitializeComponent();
        }

        ProductInfo pi = null;
        public void SetValue(object sender, EventArgs e)
        {
            //获取要修改的数据
            UpdateMemmberInfo<ProductInfo> mi = e as UpdateMemmberInfo<ProductInfo>;
            if (mi!=null)
            {
                 pi = mi.obj;
                //给窗体复制
               // pi.CatId = Convert.ToInt32(cmbCategory.SelectedValue);
                 txtName.Text = pi.ProName;
                txtCost.Text  = pi.ProCost.ToString();
                txtPrice.Text = pi.ProPrice.ToString();
                txtRemark.Text = pi.Remark;
               txtNum.Text = pi.ProNum;
               txtStock.Text = pi.ProStock.ToString();
                txtUnit.Text = pi.ProUnit;
               txtSpell.Text = pi.ProSpell;
            }
        }

       
        private void btnOk_Click(object sender, EventArgs e)
        {
         

            ProductInfo pi1 = new ProductInfo();
            pi1.CatId = Convert.ToInt32(cmbCategory.SelectedValue);
            pi1.ProName = txtName.Text;
            pi1.ProCost = Convert.ToDecimal(txtCost.Text);
            pi1.ProPrice = Convert.ToDecimal(txtPrice.Text);
            pi1.Remark = txtRemark.Text;
            pi1.ProNum = txtNum.Text;
            pi1.ProStock = Convert.ToDecimal(txtStock.Text);
            pi1.ProUnit = txtUnit.Text;
            pi1.ProSpell = txtSpell.Text;
            pi1.ProId = pi.ProId;

            ProductBLL bll = new ProductBLL();
            bool isUpdate = bll.UpdateProduct(pi1);

            if (isUpdate)
            {
                MessageBox.Show("更新成功");
                this.Close();
            }
            else
            {
                MessageBox.Show("更新失败");
                this.Close();
            }
        }


        private void FrmChangeProduct_Load(object sender, EventArgs e)
        {
       
            cmbCategory.DisplayMember = "catName";
            cmbCategory.ValueMember = "catID";
            CategoryBLL bll = new CategoryBLL();
            cmbCategory.DataSource = bll.GetCategoryInfos();
            cmbCategory.SelectedValue = pi.CatId;
        }


    }
}
